package com.Business.service;

import com.Business.dao.BaseUtilDao;
import com.Utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by XingYang on 2019/3/23.
 */
@Service
public class BusinessServiceImpl {
    @Autowired
    BaseUtilDao baseUtilDao;
    @Autowired
    RedisUtil redisUtil;

    public List<Map> getAttrs(String param){
        List<Map> list = new ArrayList<>();
        Jedis jedis = redisUtil.getClient();
        //若该配置信息不在缓存中
        //FIXME  开发时 暂不从缓存读取
     //   if(jedis.llen(param)==0){
        if(true){
            list = baseUtilDao.getAttrs(param);
            jedis.lpush(param.getBytes(),redisUtil.serializeObj(list));

        }
        else{
            list =(List<Map>) redisUtil.unSerializseObj(jedis.lrange(param.getBytes(),0,0).get(0));
        }


        return list;
    }


}
